package cn.com.scitc.licenseplateback.dao;

import cn.com.scitc.licenseplateback.model.LdleParkingEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface LdleParkingDao extends JpaRepository<LdleParkingEntity, Integer> {

    /**
     * 测试用例，向数据库添加一定量的数据
     * @param cln
     * @param reg
     * @param arr
     * @param number
     */
    @Modifying
    @Transactional
    @Query(value = "insert into LdleParking (cubeLibraryNumber, region, arrangement, number) values (:cln, :reg, :arr, :number)", nativeQuery = true)
    void addPark(String cln, String reg, int arr, String number);

    /**
     * 根据立方库编号 => 查询立方库内的空闲车位信息
     * @param cubenumber
     * @return
     */
    @Query(value = "select l  from LdleParkingEntity l where l.cubeLibraryNumber = :cubenumber")
    List<LdleParkingEntity> findAllByCubeInfo(String cubenumber);

    /**
     * 根据立方库编号、区域、楼层 进行数据的查询
     * @param cubeLibraryNumber 立方库编号
     * @param region 区域
     * @param arrangement 楼层
     * @return 实体
     */
    @Query(value = "select l from LdleParkingEntity l where l.cubeLibraryNumber = :cubeLibraryNumber and l.region = :region and l.arrangement = :arrangement")
    LdleParkingEntity findByCRA(String cubeLibraryNumber, String region, int arrangement);
}
